# 子目录 src 的 CMakeLists.txt

# 自动扫描 src 目录下的所有 .cpp 文件
file(GLOB_RECURSE SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")

# common目录
file(GLOB_RECURSE COMMON_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/common/*.cpp")

# core目录
file(GLOB_RECURSE CORE_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/core/*.cpp")

# network目录
file(GLOB_RECURSE NETWORK_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/network/*.cpp")

# storage目录
file(GLOB_RECURSE STORAGE_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/storage/*.cpp")

# service目录
file(GLOB_RECURSE SERVICE_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/service/*.cpp")

#protocol目录
file(GLOB_RECURSE PROTOCOL_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/protocols/*.cpp")

#############可执行文件${PROJECT_NAME}########################

# 添加可执行文件
add_executable(${PROJECT_NAME} 
    main.cpp 
    ${COMMON_SOURCES} 
    ${CORE_SOURCES} 
    ${NETWORK_SOURCES} 
    ${STORAGE_SOURCES} 
    ${SERVICE_SOURCES}
    ${PROTOCOL_SOURCES}
)

# 包含头文件目录
target_include_directories(${PROJECT_NAME} PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${Boost_INCLUDE_DIRS}
    ${HIREDIS_INCLUDE_DIR}
    ${ASIO_INCLUDE_DIR}
    ${MYSQL_INCLUDE_DIR}
)

    
# 链接库
target_link_libraries(${PROJECT_NAME} PRIVATE
    ${Boost_LIBRARIES}
    ${HIREDIS_LIBRARY}
    ${MYSQL_LIBRARIES}
    Threads::Threads
    nlohmann_json::nlohmann_json
    spdlog::spdlog
    OpenSSL::Crypto
)

# 拷贝配置文件
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy_if_different
        ${CMAKE_CURRENT_SOURCE_DIR}/../config/config.json
        $<TARGET_FILE_DIR:${PROJECT_NAME}>/config.json
)